package com.test;

public class TaxCalculator {
	final static double MEDICARE_LEVY_RATE		= 0.015;
	final static double TAX_NIL_MAX_INCOME		= 18200;
	final static double TAX_19C_MAX_INCOME 		= 37000;
	final static double TAX_325C_MAX_INCOME		= 80000;
	final static double TAX_37C_MAX_INCOME 		= 180000;
	
	final static double TAX_NIL_INCOME_RATE 	= 0;
	final static double TAX_19C_INCOME_RATE 	= 0.19;
	final static double TAX_325C_INCOME_RATE	= 0.325;
	final static double TAX_37C_INCOME_RATE 	= 0.37;
	final static double TAX_45C_INCOME_RATE 	= 0.45;
	
	final static double FORTNIGHT_TOTAL_AMOUNT = 26;
	
	public static double calculateAnnualGst(double annualSalary){
		double resultGST = 0;
		
        if(annualSalary > TAX_37C_MAX_INCOME) {
        	double exceedIncome = annualSalary - TAX_37C_MAX_INCOME;
        	double exceedGst = exceedIncome * TAX_45C_INCOME_RATE;
        	resultGST = exceedGst + calculateAnnualGst(TAX_37C_MAX_INCOME);
        } else if (annualSalary > TAX_325C_MAX_INCOME) {
        	double exceedIncome = annualSalary - TAX_325C_MAX_INCOME;
        	double exceedGst = exceedIncome * TAX_37C_INCOME_RATE;
        	resultGST = exceedGst + calculateAnnualGst(TAX_325C_MAX_INCOME);
        } else if (annualSalary > TAX_19C_MAX_INCOME) {
        	double exceedIncome = annualSalary - TAX_19C_MAX_INCOME;
        	double exceedGst = exceedIncome * TAX_325C_INCOME_RATE;
        	resultGST = exceedGst + calculateAnnualGst(TAX_19C_MAX_INCOME);
        } else if (annualSalary > TAX_NIL_MAX_INCOME) {
        	double exceedIncome = annualSalary - TAX_NIL_MAX_INCOME;
        	double exceedGst = exceedIncome * TAX_19C_INCOME_RATE;
        	resultGST = exceedGst + calculateAnnualGst(TAX_NIL_MAX_INCOME);
        } else {
        	resultGST = 0;;
        }
        
		return resultGST;
	}
	
	public static void main(String[] args) {
		double totalFortnightIncome = 4500;
		double fortnightSalary = 701;
		double superRate = 0.1;
		
		//Company Tax withhold
		double rCompanyTaxWithhold = totalFortnightIncome / 11d;
		double rSuperWithhold = totalFortnightIncome * 10/11d * superRate;
		
		double rFortnightGrossPay = totalFortnightIncome - rCompanyTaxWithhold - rSuperWithhold;
		
		//Calculate fortnight reimbursement pay
		double rFortnightReim = rFortnightGrossPay - fortnightSalary;
		
		//Calculate fortnight gst and medical levy
		double rFortnightMedicalLevy = fortnightSalary * MEDICARE_LEVY_RATE;
		double rAnnualGst = calculateAnnualGst(fortnightSalary * FORTNIGHT_TOTAL_AMOUNT);
		double rFortnightGst = rAnnualGst / FORTNIGHT_TOTAL_AMOUNT;
		
		double rFortnightNetIncome = fortnightSalary - rFortnightGst - rFortnightMedicalLevy;

		System.out.printf("*** Total Income %.2f ***", totalFortnightIncome);
		System.out.printf("\nCompany GST:\t%.2f%n", rCompanyTaxWithhold);
		System.out.printf("Super:\t%.2f%n", rSuperWithhold);
		System.out.printf("Money left after withhold:\t%.2f%n", rFortnightGrossPay);
		
		System.out.printf("\n*** Salary %.2f ***", fortnightSalary);
		System.out.printf("\nSalary Gst + MedicalLevy:\t%.2f%n", (rFortnightGst + rFortnightMedicalLevy));
		System.out.printf("NetIncome:\t%.2f%n", rFortnightNetIncome);
		System.out.printf("Reim:\t%.2f%n", rFortnightReim);
	}
}
